<template>
  <custom-container>
    <custom-container-header no-spacing>
      <el-form :model="filters" ref="form" :disabled="loading"
               inline size="medium"
               @submit.native.prevent="getAll"
               class="width-100"
      >
        <el-form-item label="查询时间:">
          <el-date-picker
            v-model="filters.date"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="{disabledDate: beforeToday.disabledDate}"
            value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="下级代理账号名：">
          <el-input v-model="filters.username" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" native-type="submit">查询</el-button>
        </el-form-item>

        <el-form-item v-show="true">
          <custom-button-group v-model="time">
            <custom-button v-for="period in periods" :key="period.value" :label="period.value">
              {{period.title}}
            </custom-button>
          </custom-button-group>
        </el-form-item>
      </el-form>
    </custom-container-header>
    <custom-container-body>
      <!--<el-table :data="cTableData.list" :loading="loading" element-loading-text="加载中..." border border-radius-->
                <!--:summary-method="getSummaries"-->
                <!--:local-summary-method="getLocalSummaries"-->
                <!--show-summary-->
                <!--show-local-summary-->
                <!--@sort-change="sortChange"-->
      <!--&gt;-->
      <el-table :data="cTableData.list" :loading="loading" element-loading-text="加载中..." border border-radius
                :summary-method="getSummaries"
                :local-summary-method="getLocalSummaries"
                @sort-change="sortChange"
      >
        <el-table-column
          align="center"
          label="下级代理上分时间">
          <template slot-scope="{row}">
            {{row.time | toTime}}
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="userName"
          label="下级代理账户名">
        </el-table-column>

        <el-table-column
          align="center"
          prop="beforeAmount"
          label="代理上分前">
          <template slot-scope="{row}">
            {{row.beforeAmount | currency}}
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="afterAmount"
          label="代理上分后">
          <template slot-scope="{row}">
            {{row.afterAmount | currency}}
          </template>
        </el-table-column>

        <template slot="empty">
          <div class="el-table__empty">
            <svg-icon class="el-table__empty-icon" icon-class="grid-empty-2"></svg-icon>
            <div class="el-table-text">暂无数据</div>
          </div>
        </template>
      </el-table>

      <div class="el-pagination-container">
        <el-pagination
          bordered
          @size-change="localGridSizeChange" @current-change="localGridCurrentChange"
          :current-page="filters.page" :page-size="filters.size"
          :total="tableData.total">
        </el-pagination>
      </div>
    </custom-container-body>
  </custom-container>
</template>

<script type="text/jsx">

  import {upAmountGrant as getApi,} from '@/services/api/report';

  import {detailContent, grid, pickerOption} from '@/build';

  export default {
    name: "upper-sum",

    mixins: [grid, pickerOption],

    data() {
      return {
        filters: {
          date: undefined,
          page: 1,
          size: 10,
        },
        time: consts.THIS_WEEK,
        periods: _.filter(consts.TIME_PERIOD, (period) => {
          return _.indexOf([consts.THIS_WEEK, consts.LAST_WEEK, consts.THIS_MONTH, consts.LAST_MONTH], period.value) !== -1;
        }),
        tableData: {
          list: [],
          total: 0,
        },
        // statistic: [
        //   {
        //     index: 2,
        //     prop: 'tableData.sum.beforeAmount',
        //     format: (value) => {
        //       return <div>{_.currency(value)}</div>;
        //     }
        //   },
        //   {
        //     index: 3,
        //     prop: 'tableData.sum.afterAmount',
        //     format: (value) => {
        //       return <div>{_.currency(value)}</div>;
        //     }
        //   },
        // ]
      };
    },

    watch: {
      'filters.date'() {
        this.gridSearch();
      }
    },

    mounted() {
      this.bindGet(getApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
        format: data => {
          data.list = _(data.list).map((info, date) => {
            return {
              date,
              ...info
            };
          }).orderBy(['date'], ['desc']).value();
          data.total = _.size(data.list);
          return data;
        }
      });
    }
  };

</script>

